import component from "element-plus/es/components/tree-select/src/tree-select-option.mjs"
import { createRouter,createWebHistory } from "vue-router"
import { useUserStore } from '../stores/userStore'

const routes=[
    {path:'/', name:'Index', title:'首页', component:() => import("../views/index.vue")},
    {path:'/person', name:'Preson', title:'个人主页', component:() => import("../views/person.vue"),meta: { requiresAuth: true }},
    {path:'/user', name:'User', title:'个人中心', component:() => import("../views/user/index.vue")},
    {path:'/user/list', name:'UserList', title:'个人中心', component:() => import("../views/user/List.vue")},
    {path:'/login', name:'Login', title:'登录', component:() => import("../views/login.vue")},
    {path:'/reg', name:'Reg', title:'注册', component:() => import("../views/reg.vue")},
    { path: '/platform', name: 'PlatformList', title: '平台动态', component: () => import("../views/platform/index.vue") },
    { path: '/platform/:id', name: 'PlatformDetail', title: '平台动态详情', component: () => import("../views/platform/Detail.vue") },
    { path: '/policies', name: 'PoliciesList', title: '政策法规', component: () => import("../views/policies/index.vue") },
    { path: '/policies/:id', name: 'PoliciesDetail', title: '政策法规详情', component: () => import("../views/policies/Detail.vue") },
    { path: '/complaints', name: 'ComplaintList',title: '政策法规', component: () => import("../views/complaints/index.vue") },
    { path: '/complaints/:id', name: 'ComplaintDetail',component: () => import("../views/complaints/Detail.vue")},
    { path: '/announcements',name: 'AnnouncementList',component: () => import("../views/announcements/index.vue"),props: true },// 允许将查询参数作为 props 传递给组件
    { path: '/announcements/:id', name: 'AnnouncementDetail',component: () => import("../views/announcements/Detail.vue")},
    //{ path: '/user/enterprise-info', name: 'EnterpriseInfo', title: '企业信息', component: () => import("../views/EnterpriseInfo/index.vue") },
  ];

const router=createRouter({
        history:createWebHistory(),
        routes
    }
);

router.addRoute({
  path:'/user/:id',
  name: "UserDetail",
  title:"用户详情",
  component: () => import("../views/user/Detail.vue")
})

router.beforeEach((to, from, next) => {
  const userStore = useUserStore()
  if (to.meta.requiresAuth && !userStore.isLoggedIn) {
    next('/login')
  } else {
    next();
  }
});

export default router